package com.zycx.system.role.service;

import com.zycx.common.entity.EntityUtils;
import com.zycx.common.result.ServerResponse;
import com.zycx.system.role.entity.UserRole;
import com.zycx.system.role.mapper.UserRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * Created by zycx on 2018-12-11 21:37
 * Created with IntelliJ IDEA.
 */
@Slf4j
@Service
public class UserRoleService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    public ServerResponse saveUserRole(UserRole userRole) {
        if (userRole == null) {
            return ServerResponse.errorMessage("数据不能为空");
        }
        if (StringUtils.isEmpty(userRole.getRoleId()) || StringUtils.isEmpty(userRole.getUserId())) {
            return ServerResponse.errorMessage("roleId 或 userId 不能为空");
        }
        userRole.setId(EntityUtils.getId());
        int insert = userRoleMapper.insert(userRole);
        if (insert == 0) {
            return ServerResponse.error();
        }
        return ServerResponse.successData(userRole);
    }


}
